﻿using System.IO;
using System.Xml.Serialization;
using Group_Mail;
using NUnit.Framework;

namespace Group_Mail_UnitTest
{
    [TestFixture]
    public class TestXmlSerialization
    {
        [Test]
        public void Deserialize()
        {
            var serializer = new XmlSerializer(typeof (Group));
            var fs = new FileStream("E:\\Group.xml", FileMode.Open);
            var group = (Group) serializer.Deserialize(fs);
            Assert.IsNotNull(group);
            Assert.AreEqual(2, group.Fields.Count);
            Assert.AreEqual(2, group.Recipients.Count);
        }

        [Test]
        public void Serialize()
        {
            var group = new Group {Name = "Test Group"};

            var abc = new Recipient();
            abc.SetFieldValue("Email", "nguyen.dainghia@gmail.com");
            abc.SetFieldValue("FullName", "Nguyen Dai Nghia");

            var def = new Recipient();
            def.SetFieldValue("Email", "admin@mylifevn.com");
            def.SetFieldValue("FullName", "MyLifeVn");

            group.Recipients.Add(abc);
            group.Recipients.Add(def);

            var serializer = new XmlSerializer(typeof (Group));
            var fs = new FileStream("E:\\Group.xml", FileMode.Create);
            serializer.Serialize(fs, group);
            fs.Close();
        }
    }
}